package com.fyy.redissonlock.controller;

import com.fyy.redissonlock.utils.RedissionLockUtil;
import com.fyy.redissonlock.utils.ResissonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @Author fyy
 * @Description
 * @Date 2020/7/13 10:42
 */
@RestController
@RequestMapping("/lock")
public class RedissionLockTest {

    @Autowired
    private RedissionLockUtil lockUtil;
    @Autowired
    private ResissonUtil resissonUtil;

    @GetMapping("/test")
    public void testLock() throws IOException {

        resissonUtil.getRedissonConfig();

        for (int i = 0;i < 5;i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    Boolean lockStatus = lockUtil.lock("LOCK");
                }
            }).start();
        }
    }

}
